package com.taoyuan.hotel.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taoyuan.hotel.dao.ParkDao;
import com.taoyuan.hotel.dto.ParkDetailDto;
import com.taoyuan.hotel.entity.Park;
import com.taoyuan.hotel.service.intf.ParkService;
import com.taoyuan.hotel.vo.PageBean;
import com.taoyuan.hotel.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ParkServiceImpl implements ParkService {
    @Autowired
    private ParkDao dao;

    @Override
    public R save(Park park) {
        if (dao.add(park)>0) {
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public PageBean all(int page, int limit) {
        PageHelper.startPage(page,limit);
        PageInfo<Park> PageInfo = new PageInfo<>(dao.selectAll());
        return PageBean.bean(PageInfo.getTotal(), PageInfo.getList());
    }

    @Override
    public R del(int id) {
        if(id>0){
            if (dao.del(id) > 0) {
                return R.ok();
            }else {
                return R.fail();
            }
        }
        return R.fail();
    }

    @Override
    public R update(Park park) {
        if (dao.update(park)>0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public PageBean queryPageWhere(Integer rid, int page, int limit) {
        PageHelper.startPage(page, limit);
        //3.获取分页结果
        PageInfo<Park> pageInfo=new PageInfo<>(dao.selectWhere(rid));
        //4.返回分页的数据
        return PageBean.bean(pageInfo.getTotal(), pageInfo.getList());
    }


    @Override
    public R delBatch(int[] ids) {
        if(ids!=null&&ids.length>0){
            if (dao.delBatch(ids)>0){
                return R.ok();
            }
        }
        return R.fail();
    }

    @Override
    public PageBean queryDetail(Integer rid, int page, int limit) {
        PageHelper.startPage(page, limit);
        //3.获取分页结果
        PageInfo<ParkDetailDto> pageInfo=new PageInfo<>(dao.selectDetail(rid));
        //4.返回分页的数据
        return PageBean.bean(pageInfo.getTotal(), pageInfo.getList());
    }
}
